$(function () {
    initMap();
});
//地图界面高度设置
//加载地图
function initMap() {
// 百度地图API功能
    var map = new BMap.Map("map_div");    // 创建Map实例
    map.centerAndZoom(new BMap.Point(118.386893, 35.201293), 18);  // 初始化地图,设置中心点坐标和地图级别
    //添加地图类型控件
    var size1 = new BMap.Size(10, 50);
    map.addControl(new BMap.MapTypeControl({
        offset: size1,
        mapTypes: [
            BMAP_NORMAL_MAP,
            BMAP_SATELLITE_MAP,
            BMAP_HYBRID_MAP
        ]
    }));

    // 编写自定义函数,创建标注
    function addMarker(marker) {
        //var marker = new BMap.Marker(point);
        map.addOverlay(marker);
    }

    // 随机向地图添加25个标注
    var bounds = map.getBounds();
    var sw = bounds.getSouthWest();
    var ne = bounds.getNorthEast();
    var lngSpan = Math.abs(sw.lng - ne.lng);
    var latSpan = Math.abs(ne.lat - sw.lat);
    for (var i = 0; i < 25; i++) {
        var point = new BMap.Point(sw.lng + lngSpan * (Math.random() * 0.7), ne.lat - latSpan * (Math.random() * 0.7));
        //  addMarker(point);
    }
    // var point = new BMap.Point(118.386893,35.201293);
    // addMarker(point);
    // 向地图添加标注
    // var myIcon = new BMap.Icon("images/weather/tiel.jpg", new BMap.Size(30, 30));

    var steelContent = '' +
        '<div >' +
        // '<img style="width: 100%;height: 150px" src="images/weather/bjsndds.jpg"/>' +
        '</div>'+
        '<div style="width: 100%;height: 30px; background-color: #ff615d;text-align: center;font-size: 20px;color: #ffffff"><span>1#土壤墒情数据</span></div>' +
        '<div><span></span></div>' +
        '<div><span style="font-size: 18px;">土壤湿度:</span><span style="float: right;font-size: 18px;color: #CCCCCC"> 5℃</span></div>' +
        '<hr>' +
        '<div><span style="font-size: 18px;">土壤温度:</span><span style="float: right;font-size: 18px;color: #CCCCCC"> 34%</span></div>' +
        '<hr>' +
        '<div><span style="font-size: 18px;">土壤PH值:</span><span style="float: right;font-size: 18px;color: #CCCCCC">8</span></div>' +
        '<hr>' +
        '<div><span style="font-size: 18px;">土壤盐分:</span><span style="float: right;font-size: 18px;color: #CCCCCC">267</span></div>'+
        '';

    var shexiangtou = '' +
        '<div >' +
        '<img class="dddn"  title="点击查看视频监控"  style="width: 100%;height: 150px;cursor:pointer" src="images/qiangji.png"/>' +
        '</div>' +
        '<div class="dddn"  title="点击查看视频监控" style="width: 100%;height: 30px; background-color: #ffcd4d;text-align: center;font-size: 20px;color: #ffffff;cursor:pointer"><span>1#枪击摄像头</span></div>' ;

    var win = [new Openwin(250, 280, ""), new Openwin(200, 190, "")];

    var icon = [new BMap.Icon("images/weather/tiel.jpg", new BMap.Size(30, 30)), new BMap.Icon("images/weather/sxt.jpg", new BMap.Size(30, 30))];
    var lx = [[118.386893, 35.201293], [118.38847, 35.201282]];
    var point = new BMap.Point(lx [0][0], lx [0][1]);
    var marker = new BMap.Marker(point, {icon: icon[0]});

      var infowindow =  new BMap.InfoWindow(shexiangtou, win[1]);
    marker.addEventListener("mouseover", function (e) {
        this.openInfoWindow(new BMap.InfoWindow(steelContent, win[0]));
    });
    addMarker(marker);
    var pointsxt = new BMap.Point(lx [1][0], lx [1][1]);
    var markersxt = new BMap.Marker(pointsxt, {icon: icon[1]});
    markersxt.addEventListener("mouseover", function (e) {
        this.openInfoWindow(infowindow);
    });
    addMarker(markersxt);
    infowindow.addEventListener('open',function (e) {

      $(".dddn").on('click',function () {
        $('.container').attr('style', 'visibility: visible').find('.pop-up').eq(0).attr('style', 'visibility: visible').siblings().attr('style', 'visibility: hidden');
      });
      // document.getElementsByClassName("dddn").onclick = function(){
      //
      // }
    });
    // 创建标注对象并添加到地图


    map.setCurrentCity("临沂");          // 设置地图显示的城市 此项是必须设置的
    map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
    //设备地图颜色
    var mapStyle = {
        style: "midnight"
    };
    map.setMapStyle(mapStyle);
    //加载城市控件
    var size = new BMap.Size(10, 50);
    map.addControl(new BMap.CityListControl({
        anchor: BMAP_ANCHOR_TOP_LEFT,
        offset: size,
    }));


    function Openwin(width, higth, title) {
        this.width = width;     //信息窗口宽度
        this.height = higth;     //信息窗口高度
        this.title = title; //信息窗口标题
        this.enableMessage = true;	//设置允许信息窗发送短息
    }
}

